using System.Security.Claims;
using DealerPlatform.Core.Consts;
using Microsoft.AspNetCore.Mvc.Filters;

namespace DealerPlatform.Web.Filters;

public class CtmAuthorizationFilterAttribute : Attribute, IAuthorizationFilter
{
    public void OnAuthorization(AuthorizationFilterContext context)
    {
        var user = context.HttpContext.User;
        ClaimsIdentity claimsIdentity = user.Identity as ClaimsIdentity;
        foreach (var claim in claimsIdentity.Claims)
        {
            if (claim.Type==HttpContextItemKeyName.CUSTOMER_NO)
            {
                context.HttpContext.Items.Add(HttpContextItemKeyName.CUSTOMER_NO,claim.Value);
            }
        }
    }
}